package com.example.hello.aspect;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;


@Component
@Aspect
public class TaskAspect {

    @Pointcut("execution(* com.example.springtask.Scheduler.ShopScheduler.*(..))")
    public void taskExecution() {
    }

    @Before("taskExecution()")
    public void beforeTaskExecution(JoinPoint joinPoint) {
        System.out.println("任务即将执行: " + joinPoint.getSignature());
    }

    @After("taskExecution()")
    public void afterTaskExecution(JoinPoint joinPoint) {
        System.out.println("任务执行完毕: " + joinPoint.getSignature());
    }

    @AfterThrowing(pointcut = "taskExecution()", throwing = "ex")
    public void handleTaskException(JoinPoint joinPoint, Exception ex) {
        System.out.println("任务执行出现异常: " + ex.getMessage());
    }

}
